var click_counter = 0;
jQuery(document).ready(function() {
    display_list_item();
    jQuery(".loading_icon_img").click(function(){
       rotate_loading();
       show_more_loading();
    });
    
});
function display_list_item(counter){
    var page = get_url_query('page');
    if(page>0){
        jQuery('#loading_icon').hide();
    }else{
        jQuery('.list_item').hide();
        jQuery('.pager').hide();
        for(var i=0;i<Drupal.settings.show_number;i++){
            jQuery('#list_item_'+i).show();
        }
        //if list item less then current display then, hide loading button
        if(jQuery('.list_item').size()<=Drupal.settings.show_number*(click_counter+1)){
            jQuery('#loading_icon').hide();
            jQuery('.pager').show();
        }
    }
}

function get_url_query(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r !== null) return unescape(r[2]); return null;
}
function show_more_loading(){
    var start_id = Drupal.settings.show_number*(click_counter+1);
    var end_id = Drupal.settings.show_number*(click_counter+2);
    for(var i=start_id;i<(end_id);i++){
        jQuery('#list_item_'+i).fadeIn();
    }
    //if list item less then current display then, hide loading button
    if(jQuery('.list_item').size()<=end_id){
        jQuery('#loading_icon').hide();
        jQuery('.pager').show();
    }
    click_counter++;
}
function rotate_loading(){
    jQuery(".loading_icon_img").animate(
        {transform: 360},
        {  
            duration: 1000,  
            step: function(now, fx) {  
                if (fx.prop === "transform") {  
                    if (now > 90) {  // rotate and fade in when image already rotated 360deg
                        jQuery(this).css({  
                            '-webkit-transform': 'rotate(-' + now + 'deg)',  //Safari 3.1+, Chrome  
                            '-moz-transform': 'rotate(-' + now + 'deg)',     //Firefox 3.5-15  
                            '-ms-transform': 'rotate(-' + now + 'deg)',      //IE9+  
                            '-o-transform': 'rotate(-' + now + 'deg)',       //Opera 10.5-12.00  
                            'transform': 'rotate(-' + now + 'deg)'        //Firefox 16+, Opera 12.50+  
                        });
                    }  
                }  
            }  
        }
    );
}